const UserModel = require('../Model/user');

class userModel {

    // 用户注册
    static async create(ctx,next){
        //接收客服端
        let req = ctx.request.body;
        if(req.username && req.nickname && req.password){
           let ret = await UserModel.create({
                username:req.username,
                nickname:req.nickname,
                avator:req.avator,
                password:req.password,
                mobile:req.mobile
            });
            let data = await UserModel.UserInfo(ret.id);
            ctx.response.status = 200;
            ctx.body = {
                code: 200,
                msg: '注册成功',
                data
            }
        }else{
            ctx.response.status = 416;
            ctx.body = {
                code: 200,
                msg: '参数不齐全'
            }
        }
    }

    static async UserInfo(ctx,next){
        console.log(ctx)
        let data = await UserModel.UserInfo(ctx.query.id);
        ctx.response.status = 200;
        ctx.body = {
            code: 200,
            msg: '查询成功',
            data
        }
    }
}

module.exports = userModel;